using Google.ProtocolBuffers;
using MicroMsg.Common.Algorithm;
using micromsgBackground;
using MicroMsgBackground.Network;
using Microsoft.Phone.Info;
using System;
using System.IO;
using System.IO.IsolatedStorage;
using System.Linq;
using System.Text;
using System.Windows.Media.Imaging;
namespace MicroMsgBackground.Common.Utils
{
	public class Util
	{
		public const string TAG = "util";
		public const long MILLSECONDS_OF_SECOND = 1000L;
		public const long MILLSECONDS_OF_MINUTE = 60000L;
		public const long MILLSECONDS_OF_HOUR = 3600000L;
		public const long MILLSECONDS_OF_DAY = 86400000L;
		public const string fmt_justnow = "1分钟内";
		public const string fmt_in60min = "{0}分钟前";
		public const string fmt_dawn = "凌晨";
		public const string fmt_morning = "早上";
		public const string fmt_noon = "中午";
		public const string fmt_afternoon = "下午";
		public const string fmt_evening = "晚上";
		public const string fmt_pre_today = "今天";
		public const string fmt_pre_yesterday = "昨天";
		public const string fmt_patime = "h:mm";
		public const string fmt_date = "M月d日";
		public const string fmt_datetime = "M月d日 {0}hh:mm";
		public const string fmt_longdate = "yyyy年M月d日";
		public const string fmt_longtime = "yyyy年M月d日 {0}hh:mm";
		private const long mms2ms = 10000L;
		public const int ONE_2GPACK_UPLOADSIZE = 8192;
		public const int ONE_3GPACK_UPLOADSIZE = 16384;
		public const int ONE_WIFIPACK_UPLOADSIZE = 32768;
		private static UTF8Encoding encoding = new UTF8Encoding();
		public static string[] EnglishMonth = new string[]
		{
			"Jan",
			"Feb",
			"Mar",
			"Apr",
			"May",
			"Jun",
			"Jul",
			"Aug",
			"Sep",
			"Oct",
			"Nov",
			"Dec"
		};
		public static string[] ChineseMonth = new string[]
		{
			"1月",
			"2月",
			"3月",
			"4月",
			"5月",
			"6月",
			"7月",
			"8月",
			"9月",
			"10月",
			"11月",
			"12月"
		};
		private static char[] InvalidkeyNameChars;
		public static IsolatedStorageFile m_storageFile = IsolatedStorageFile.GetUserStoreForApplication();
		private static string[] Day = new string[]
		{
			"周日",
			"周一",
			"周二",
			"周三",
			"周四",
			"周五",
			"周六"
		};
		private static string[] DayEn = new string[]
		{
			"Sunday",
			"Monday",
			"Tuesday ",
			"Wednesday",
			"Thursday",
			"Friday",
			"Saturday"
		};
		private static string[] DayTW = new string[]
		{
			"周日",
			"周一",
			"周二",
			"周三",
			"周四",
			"周五",
			"周六"
		};
		private static string gDeviceID = null;
		public static long timeCur;
		public static bool InvalidFileName(string keyName)
		{
			if (string.IsNullOrEmpty(keyName))
			{
				return true;
			}
			if (Util.InvalidkeyNameChars == null)
			{
				char[] invalidPathChars = Path.GetInvalidPathChars();
				Util.InvalidkeyNameChars = new char[invalidPathChars.Length + 2];
				Array.Copy(invalidPathChars, Util.InvalidkeyNameChars, invalidPathChars.Length);
				Util.InvalidkeyNameChars[invalidPathChars.Length] = '/';
				Util.InvalidkeyNameChars[invalidPathChars.Length + 1] = '\\';
			}
			return 0 <= keyName.IndexOfAny(Util.InvalidkeyNameChars);
		}
		public static bool InvalidPathName(string keyName)
		{
			return string.IsNullOrEmpty(keyName) || 0 <= keyName.IndexOfAny(Path.GetInvalidPathChars());
		}
		public static int CheckSum(string string_0)
		{
			if (string.IsNullOrEmpty(string_0))
			{
				return 0;
			}
			int num = 0;
			for (int i = 0; i < string_0.get_Length(); i++)
			{
				char c = string_0.get_Chars(i);
				num += (int)c;
			}
			return num;
		}
		public static int CheckSum(byte[] data)
		{
			if (data == null)
			{
				return 0;
			}
			int num = 0;
			for (int i = 0; i < data.Length; i++)
			{
				byte b = data[i];
				num += (int)b;
			}
			return num;
		}
		public static byte[] StringToByteArray(string string_0)
		{
			return Util.encoding.GetBytes(Util.NullAsNil(string_0));
		}
		public static string ByteArrayToString(byte[] byte_0)
		{
			byte_0 = Util.NullAsNil(byte_0);
			return Util.encoding.GetString(byte_0, 0, byte_0.Length);
		}
		public static string NullAsNil(string string_0)
		{
			if (string_0 != null)
			{
				return string_0;
			}
			return "";
		}
		public static byte[] NullAsNil(byte[] byte_0)
		{
			if (byte_0 != null)
			{
				return byte_0;
			}
			return new byte[0];
		}
		public static string toHexString(byte[] Bytes)
		{
			string text = "";
			for (int i = 0; i < Bytes.Length; i++)
			{
				byte b = Bytes[i];
				text += b.ToString("X");
			}
			return text;
		}
		public static string toHexString(byte[] Bytes, int int_0)
		{
			string text = "";
			int_0 = Math.Min(int_0, Bytes.Length);
			for (int i = 0; i < int_0; i++)
			{
				text += Bytes[i].ToString("X");
			}
			return text;
		}
		public static byte[] toFixLenString(string string_0, int int_0)
		{
			byte[] bytes = Encoding.get_UTF8().GetBytes(string_0);
			byte[] array = new byte[int_0];
			Arrays.fill(array, 0);
			int num = 0;
			while (num < bytes.Length && num < array.Length)
			{
				array[num] = bytes[num];
				num++;
			}
			return array;
		}
		public static string capitalString(string string_0)
		{
			if (string_0 == null || string_0.get_Length() == 0)
			{
				return "";
			}
			if (string_0.get_Length() == 1)
			{
				return string_0.ToUpper();
			}
			return string_0.Substring(0, 1).ToUpper() + string_0.Substring(1, string_0.get_Length() - 1);
		}
		public static byte[] byteArrayClone(byte[] buffer)
		{
			if (buffer == null)
			{
				return null;
			}
			byte[] array = new byte[buffer.Length];
			Array.Copy(buffer, array, buffer.Length);
			return array;
		}
		public static bool byteArrayEqual(byte[] byte_0, byte[] byte_1)
		{
			return (byte_0 == null && byte_1 == null) || (byte_0 != null && byte_1 != null && byte_0.Length == byte_1.Length && Enumerable.SequenceEqual<byte>(byte_0, byte_1));
		}
		public static void debugBuffer(string string_0, byte[] byte_0, int offset, int count, int int_0)
		{
			if (count > int_0)
			{
				Util.debugBuffer(string_0, byte_0, offset, int_0);
				return;
			}
			Util.debugBuffer(string_0, byte_0, offset, count);
		}
		public static void debugBuffer(string string_0, byte[] byte_0, int offset, int count)
		{
			for (int i = 0; i < count; i += 16)
			{
				int num = 16;
				if (16 > count - i)
				{
					num = count - i;
				}
				BitConverter.ToString(byte_0, offset + i, num).Replace("-", " 0x");
			}
		}
		public static void debugBuffer(string string_0, byte[] byte_0)
		{
			Util.debugBuffer(string_0, byte_0, 0, byte_0.Length);
		}
		public static void debugBuffer(byte[] byte_0)
		{
			Util.debugBuffer("-", byte_0);
		}
		public static void saveDataToFile(byte[] data, int offset, int count, string fileName)
		{
			using (IsolatedStorageFileStream isolatedStorageFileStream = new IsolatedStorageFileStream(fileName, 2, Util.m_storageFile))
			{
				isolatedStorageFileStream.Write(data, offset, count);
			}
		}
		public static int loadDataFromFile(ref byte[] data, string fileName)
		{
			int result = 0;
			using (IsolatedStorageFileStream isolatedStorageFileStream = new IsolatedStorageFileStream(fileName, 3, Util.m_storageFile))
			{
				result = isolatedStorageFileStream.Read(data, 0, data.Length);
			}
			return result;
		}
		public static SKBuiltinString_t toSKString(string inStr)
		{
			SKBuiltinString_t defaultInstance = SKBuiltinString_t.DefaultInstance;
			SKBuiltinString_t.Builder builder = SKBuiltinString_t.CreateBuilder();
			builder.String = ((inStr == null) ? "" : inStr);
			return builder.Build();
		}
		public static SKBuiltinBuffer_t toSKBuffer(string inStr)
		{
			SKBuiltinBuffer_t defaultInstance = SKBuiltinBuffer_t.DefaultInstance;
			SKBuiltinBuffer_t.Builder builder = new SKBuiltinBuffer_t.Builder();
			if (string.IsNullOrEmpty(inStr))
			{
				builder.ILen = 0u;
			}
			else
			{
				builder.Buffer = ByteString.CopyFromUtf8(inStr);
				builder.ILen = (uint)builder.Buffer.Length;
			}
			return builder.Build();
		}
		public static SKBuiltinBuffer_t toSKBuffer(byte[] inBytes)
		{
			SKBuiltinBuffer_t defaultInstance = SKBuiltinBuffer_t.DefaultInstance;
			SKBuiltinBuffer_t.Builder builder = new SKBuiltinBuffer_t.Builder();
			if (inBytes == null)
			{
				builder.ILen = 0u;
			}
			else
			{
				builder.Buffer = ByteString.CopyFrom(inBytes);
				builder.ILen = (uint)builder.Buffer.Length;
			}
			return builder.Build();
		}
		public static SKBuiltinBuffer_t toSKBuffer(byte[] inBytes, int offset, int count)
		{
			SKBuiltinBuffer_t defaultInstance = SKBuiltinBuffer_t.DefaultInstance;
			SKBuiltinBuffer_t.Builder builder = new SKBuiltinBuffer_t.Builder();
			if (inBytes == null)
			{
				builder.ILen = 0u;
			}
			else
			{
				builder.Buffer = ByteString.CopyFrom(inBytes, offset, count);
				builder.ILen = (uint)builder.Buffer.Length;
			}
			return builder.Build();
		}
		public static int writeInt(int value, ref byte[] byte_0, ref int offset)
		{
			byte_0[offset] = (byte)(value >> 24 & 255);
			byte_0[offset + 1] = (byte)(value >> 16 & 255);
			byte_0[offset + 2] = (byte)(value >> 8 & 255);
			byte_0[offset + 3] = (byte)(value & 255);
			offset += 4;
			return offset;
		}
		public static int writeShort(short value, ref byte[] byte_0, ref int offset)
		{
			byte_0[offset] = (byte)(value >> 8 & 255);
			byte_0[offset + 1] = (byte)(value & 255);
			offset += 2;
			return offset;
		}
		public static int writeByte(byte value, ref byte[] byte_0, ref int offset)
		{
			byte_0[offset] = value;
			offset++;
			return offset;
		}
		public static int writeBuffer(byte[] byte_0, ref byte[] destbuf, ref int offset)
		{
			Buffer.BlockCopy(byte_0, 0, destbuf, offset, byte_0.Length);
			offset += byte_0.Length;
			return offset;
		}
		public static int readInt(byte[] byte_0, ref int offset)
		{
			int num = (int)byte_0[offset];
			int num2 = (int)byte_0[offset + 1];
			int num3 = (int)byte_0[offset + 2];
			int num4 = (int)byte_0[offset + 3];
			offset += 4;
			return (num << 24) + (num2 << 16) + (num3 << 8) + num4;
		}
		public static short readShort(byte[] byte_0, ref int offset)
		{
			int num = (int)byte_0[offset];
			int num2 = (int)byte_0[offset + 1];
			offset += 2;
			return (short)((num << 8) + num2);
		}
		public static byte readByte(byte[] byte_0, ref int offset)
		{
			byte result = byte_0[offset];
			offset++;
			return result;
		}
		public static int readBuffer(byte[] srcbuf, ref int offset, ref byte[] destbuf, int count)
		{
			Buffer.BlockCopy(srcbuf, offset, destbuf, 0, count);
			offset += count;
			return count;
		}
		public static string getCutPasswordMD5(string rawPsw)
		{
			if (rawPsw == null)
			{
				rawPsw = "";
			}
			if (rawPsw.get_Length() <= 16)
			{
				return Util.getFullPasswordMD5(rawPsw);
			}
			return Util.getFullPasswordMD5(rawPsw.Substring(0, 16));
		}
		public static string getFullPasswordMD5(string string_0)
		{
			return MD5Core.GetHashString(string_0, Encoding.get_UTF8());
		}
		public static int stringToInt(string string_0)
		{
			if (string.IsNullOrEmpty(string_0))
			{
				return 0;
			}
			int result = 0;
			try
			{
				result = (int)long.Parse(string_0, 7);
			}
			catch (Exception ex)
			{
				Log.smethod_5("util", "stringToInt error:" + ex.ToString());
			}
			return result;
		}
		public static string formatPrefixInDay(long timeInDay)
		{
			long num = 21600000L;
			long num2 = 43200000L;
			long num3 = 46800000L;
			long num4 = 64800000L;
			if (timeInDay < 0L)
			{
				return "";
			}
			string result;
			if (timeInDay < num)
			{
				result = "凌晨";
			}
			else
			{
				if (timeInDay < num2)
				{
					result = "早上";
				}
				else
				{
					if (timeInDay < num3)
					{
						result = "中午";
					}
					else
					{
						if (timeInDay < num4)
						{
							result = "下午";
						}
						else
						{
							result = "晚上";
						}
					}
				}
			}
			return result;
		}
		public static long Tick2ms(long tick)
		{
			return tick / 10000L;
		}
		public static long ms2Tick(long long_0)
		{
			return long_0 * 10000L;
		}
		public static bool isYesterday(DateTime currentTime, DateTime yesterday)
		{
			DateTime dateTime = new DateTime(currentTime.get_Year(), currentTime.get_Month(), currentTime.get_Day());
			DateTime dateTime2 = new DateTime(yesterday.get_Year(), yesterday.get_Month(), yesterday.get_Day());
			TimeSpan timeSpan = dateTime.Subtract(dateTime2);
			return timeSpan.get_TotalDays() >= 1.0 && timeSpan.get_TotalDays() < 2.0;
		}
		public static string getFormatTime(DateTime localTime)
		{
			string text = "";
			return text + localTime.ToString("HH:mm");
		}
		public static long getNowMilliseconds()
		{
			DateTime dateTime = DateTime.get_Now().ToUniversalTime();
			DateTime dateTime2 = new DateTime(1970, 1, 1);
			double totalMilliseconds = dateTime.Subtract(dateTime2).get_TotalMilliseconds();
			return (long)totalMilliseconds;
		}
		public static long getNowSeconds()
		{
			DateTime dateTime = DateTime.get_Now().ToUniversalTime();
			DateTime dateTime2 = new DateTime(1970, 1, 1);
			double totalSeconds = dateTime.Subtract(dateTime2).get_TotalSeconds();
			return (long)totalSeconds;
		}
		public static int getNowDays()
		{
			DateTime dateTime = DateTime.get_Now().ToUniversalTime();
			DateTime dateTime2 = new DateTime(1970, 1, 1);
			return (int)dateTime.Subtract(dateTime2).get_TotalDays();
		}
		public static DateTime ToUniversalTime(DateTime dateTime_0)
		{
			return dateTime_0 - TimeSpan.FromHours(8.0);
		}
		public static DateTime ToChinaTime(DateTime dateTime_0)
		{
			return dateTime_0 + TimeSpan.FromHours(8.0);
		}
		public static long Java2CSharpMs(long javaTime)
		{
			DateTime dateTime_ = new DateTime(1970, 1, 1);
			dateTime_ = dateTime_.AddMilliseconds((double)javaTime);
			dateTime_ = Util.ToChinaTime(dateTime_);
			return Util.Tick2ms(dateTime_.get_Ticks());
		}
		public static DateTime SencondsToLocalTime(long seconds)
		{
			DateTime dateTime = new DateTime(1970, 1, 1).ToLocalTime();
			DateTime result;
			try
			{
				dateTime = dateTime.AddSeconds((double)seconds);
				goto IL_74;
			}
			catch (Exception ex)
			{
				Log.smethod_5("util", string.Concat(new object[]
				{
					"SencondsToLocalTime error:",
					ex.get_Message(),
					"  seconds:",
					seconds
				}));
				result = DateTime.get_Now().ToLocalTime();
			}
			return result;
			IL_74:
			return dateTime.ToLocalTime();
		}
		public static string nullAsNil(string string_0)
		{
			if (string_0 == null)
			{
				return "";
			}
			return string_0;
		}
		public static string dotFormat(uint number)
		{
			string text = number.ToString("n");
			return text.Substring(0, text.get_Length() - 3);
		}
		public static string getDeviceUniqueId()
		{
			if (Util.gDeviceID != null)
			{
				return Util.gDeviceID;
			}
			byte[] array = DeviceExtendedProperties.GetValue("DeviceUniqueId") as byte[];
			string text = null;
			if (array != null)
			{
				text = Util.toHexString(array);
			}
			if (text == null)
			{
				text = "wphone1234567890";
			}
			int length = text.get_Length();
			if (length > 14)
			{
				Util.gDeviceID = "wp" + text.Substring(0, 14);
			}
			else
			{
				Util.gDeviceID = "wp" + text + "wphone1234567890".Substring(0, 14 - length);
			}
			return Util.gDeviceID;
		}
		public static bool saveThumb(Stream origStream, Stream targStream, int targetWidth, int targetHeight, int quality)
		{
			if (origStream != null && targStream != null)
			{
				bool result;
				try
				{
					BitmapImage bitmapImage = new BitmapImage();
					bitmapImage.SetSource(origStream);
					WriteableBitmap writeableBitmap = new WriteableBitmap(bitmapImage);
					if (writeableBitmap.get_PixelHeight() <= targetHeight && writeableBitmap.get_PixelWidth() <= targetWidth)
					{
						Extensions.SaveJpeg(writeableBitmap, targStream, writeableBitmap.get_PixelWidth(), writeableBitmap.get_PixelHeight(), 0, quality);
					}
					else
					{
						double num;
						if (writeableBitmap.get_PixelHeight() > writeableBitmap.get_PixelWidth())
						{
							num = (double)writeableBitmap.get_PixelHeight() * (1.0 / (double)targetHeight);
						}
						else
						{
							num = (double)writeableBitmap.get_PixelWidth() * (1.0 / (double)targetWidth);
						}
						double num2 = (double)writeableBitmap.get_PixelWidth() / num;
						double num3 = (double)writeableBitmap.get_PixelHeight() / num;
						int num4 = (int)num2;
						int num5 = (int)num3;
						Log.smethod_5("util", "iScale = " + num);
						Extensions.SaveJpeg(writeableBitmap, targStream, num4, num5, 0, quality);
					}
					return true;
				}
				catch (Exception ex)
				{
					Log.smethod_1("util", ex.get_Message());
					result = false;
				}
				return result;
			}
			return false;
		}
		public static byte[] toJpeg(Stream origStream, int targetWidth = 132, int targetHeight = 132, int quality = 70)
		{
			MemoryStream memoryStream = new MemoryStream();
			if (!Util.saveThumb(origStream, memoryStream, targetWidth, targetHeight, quality))
			{
				return null;
			}
			return memoryStream.ToArray();
		}
		public static bool saveJpeg(Stream origStream, string fileName, int targetWidth = 132, int targetHeight = 132, int quality = 70)
		{
			try
			{
				using (IsolatedStorageFile userStoreForApplication = IsolatedStorageFile.GetUserStoreForApplication())
				{
					using (IsolatedStorageFileStream isolatedStorageFileStream = new IsolatedStorageFileStream(fileName, 2, userStoreForApplication))
					{
						if (!Util.saveThumb(origStream, isolatedStorageFileStream, targetWidth, targetHeight, quality))
						{
							bool result = false;
							return result;
						}
					}
				}
			}
			catch (Exception object_)
			{
				Log.smethod_1("util", object_);
				bool result = false;
				return result;
			}
			return true;
		}
		public static bool reSizePic(Stream origStream, Stream targStream, int targetWidth, int targetHeight, int quality)
		{
			if (origStream != null && targStream != null)
			{
				bool result;
				try
				{
					BitmapImage bitmapImage = new BitmapImage();
					bitmapImage.SetSource(origStream);
					WriteableBitmap writeableBitmap = new WriteableBitmap(bitmapImage);
					Extensions.SaveJpeg(writeableBitmap, targStream, targetWidth, targetHeight, 0, quality);
					return true;
				}
				catch (Exception ex)
				{
					Log.smethod_1("util", ex.get_Message());
					result = false;
				}
				return result;
			}
			return false;
		}
		public static Stream bitmapToStream(BitmapSource image)
		{
			MemoryStream memoryStream = new MemoryStream();
			WriteableBitmap writeableBitmap = new WriteableBitmap(image);
			Extensions.SaveJpeg(writeableBitmap, memoryStream, image.get_PixelWidth(), image.get_PixelHeight(), 0, 100);
			memoryStream.Seek(0L, 0);
			return memoryStream;
		}
		public static BitmapSource streamToBitmap(Stream stream)
		{
			BitmapImage bitmapImage = new BitmapImage();
			bitmapImage.SetSource(stream);
			return new WriteableBitmap(bitmapImage);
		}
		public static int getSendPackSize()
		{
			if (NetworkDeviceWatcher.isCurrentWifi())
			{
				Log.smethod_4("util", "Current net is Wifi");
				return 32768;
			}
			if (NetworkDeviceWatcher.isCurrentCell3G())
			{
				Log.smethod_4("util", "Current net is 3G");
				return 16384;
			}
			if (NetworkDeviceWatcher.isCurrentCell2G())
			{
				Log.smethod_4("util", "Current net is 2G");
				return 8192;
			}
			Log.smethod_4("util", "Current net is UnKnow");
			return 16384;
		}
		public static bool zoomCompressImage(Stream origStream, Stream targStream, int targetWidth, int targetHeight, int quality, int maxFileSize)
		{
			if (origStream != null && targStream != null && targetWidth > 0 && targetHeight > 0 && quality > 0 && maxFileSize > 0)
			{
				try
				{
					BitmapImage bitmapImage = new BitmapImage();
					bitmapImage.SetSource(origStream);
					WriteableBitmap writeableBitmap = new WriteableBitmap(bitmapImage);
					if (bitmapImage.get_PixelWidth() <= targetWidth && bitmapImage.get_PixelHeight() <= targetHeight && origStream.get_Length() <= (long)maxFileSize)
					{
						Extensions.SaveJpeg(writeableBitmap, targStream, writeableBitmap.get_PixelWidth(), writeableBitmap.get_PixelHeight(), 0, quality);
						bool result = true;
						return result;
					}
					if (bitmapImage.get_PixelWidth() > targetWidth || bitmapImage.get_PixelHeight() > targetHeight)
					{
						double num = (double)bitmapImage.get_PixelHeight() * (1.0 / (double)targetHeight);
						double num2 = (double)bitmapImage.get_PixelWidth() * (1.0 / (double)targetWidth);
						double num3 = (num > num2) ? num : num2;
						double num4 = (double)writeableBitmap.get_PixelWidth() / num3;
						double num5 = (double)writeableBitmap.get_PixelHeight() / num3;
						int num6 = (int)num4;
						int num7 = (int)num5;
						Log.smethod_4("util", "iScale = " + num3);
						using (MemoryStream memoryStream = new MemoryStream())
						{
							Extensions.SaveJpeg(writeableBitmap, memoryStream, num6, num7, 0, quality);
							if (memoryStream.get_Length() > (long)maxFileSize)
							{
								Extensions.SaveJpeg(writeableBitmap, targStream, num6, num7, 0, 50);
							}
							else
							{
								memoryStream.Seek(0L, 0);
								memoryStream.CopyTo(targStream);
							}
						}
						bool result = true;
						return result;
					}
					if (origStream.get_Length() > (long)maxFileSize)
					{
						if (origStream.get_Length() >= 153600L)
						{
							quality = 30;
						}
						else
						{
							if (origStream.get_Length() >= 133120L)
							{
								quality = 40;
							}
							else
							{
								if (origStream.get_Length() >= 102400L)
								{
									quality = 50;
								}
							}
						}
						Log.smethod_4("util", "quality = " + quality);
						Extensions.SaveJpeg(writeableBitmap, targStream, writeableBitmap.get_PixelWidth(), writeableBitmap.get_PixelHeight(), 0, quality);
						bool result = true;
						return result;
					}
				}
				catch (Exception ex)
				{
					Log.smethod_1("util", ex.get_Message());
					bool result = false;
					return result;
				}
				return true;
			}
			return false;
		}
		public static double getTimeSpan()
		{
			long num = Util.timeCur;
			Util.timeCur = DateTime.get_Now().get_Ticks();
			return TimeSpan.FromTicks(Util.timeCur - num).get_TotalMilliseconds();
		}
		public static long getCurrentTick()
		{
			return DateTime.get_Now().get_Ticks();
		}
		public static long getTimeSpan(long tick)
		{
			return (long)TimeSpan.FromTicks(DateTime.get_Now().get_Ticks() - tick).get_TotalMilliseconds();
		}
		public static ImgRet compressImage(Stream origStream, Stream targStream, int targetWidth, int targetHeight, int quality, int maxFileSize)
		{
			if (origStream != null && targStream != null && targetWidth > 0 && targetHeight > 0 && quality > 0 && maxFileSize > 0)
			{
				try
				{
					BitmapImage bitmapImage = new BitmapImage();
					bitmapImage.SetSource(origStream);
					WriteableBitmap writeableBitmap = new WriteableBitmap(bitmapImage);
					if (writeableBitmap.get_PixelWidth() <= targetWidth && writeableBitmap.get_PixelHeight() <= targetHeight && origStream.get_Length() <= (long)maxFileSize)
					{
						Extensions.SaveJpeg(writeableBitmap, targStream, writeableBitmap.get_PixelWidth(), writeableBitmap.get_PixelHeight(), 0, quality);
						ImgRet result = new ImgRet(writeableBitmap.get_PixelWidth(), writeableBitmap.get_PixelHeight(), origStream.get_Length());
						return result;
					}
					if (writeableBitmap.get_PixelWidth() > targetWidth || writeableBitmap.get_PixelHeight() > targetHeight)
					{
						double num = (double)writeableBitmap.get_PixelHeight() * (1.0 / (double)targetHeight);
						double num2 = (double)writeableBitmap.get_PixelWidth() * (1.0 / (double)targetWidth);
						double num3 = (num > num2) ? num : num2;
						double num4 = (double)writeableBitmap.get_PixelWidth() / num3;
						double num5 = (double)writeableBitmap.get_PixelHeight() / num3;
						int num6 = (int)num4;
						int num7 = (int)num5;
						Log.smethod_4("util", "iScale = " + num3);
						using (MemoryStream memoryStream = new MemoryStream())
						{
							Extensions.SaveJpeg(writeableBitmap, memoryStream, num6, num7, 0, quality);
							if (memoryStream.get_Length() > (long)maxFileSize)
							{
								Extensions.SaveJpeg(writeableBitmap, targStream, num6, num7, 0, 50);
							}
							else
							{
								memoryStream.Seek(0L, 0);
								memoryStream.CopyTo(targStream);
							}
						}
						ImgRet result = new ImgRet(num6, num7, targStream.get_Length());
						return result;
					}
					if (origStream.get_Length() > (long)maxFileSize)
					{
						if (origStream.get_Length() >= 153600L)
						{
							quality = 30;
						}
						else
						{
							if (origStream.get_Length() >= 133120L)
							{
								quality = 40;
							}
							else
							{
								if (origStream.get_Length() >= 102400L)
								{
									quality = 50;
								}
							}
						}
						Log.smethod_4("util", "quality = " + quality);
						Extensions.SaveJpeg(writeableBitmap, targStream, writeableBitmap.get_PixelWidth(), writeableBitmap.get_PixelHeight(), 0, quality);
						ImgRet result = new ImgRet(writeableBitmap.get_PixelWidth(), writeableBitmap.get_PixelHeight(), targStream.get_Length());
						return result;
					}
				}
				catch (Exception ex)
				{
					Log.smethod_1("util", ex.get_Message());
					ImgRet result = null;
					return result;
				}
				return new ImgRet(targetWidth, targetHeight, targStream.get_Length());
			}
			return null;
		}
	}
}
